#!/usr/bin/perl
# 
# Exercise 11.1
# 
# Use File::Find and the file test operators to find the oldest and largest files on the 
# hard drive of your computer. (You can delete them or store them elsewhere if 
# you're running short on disk space.)
#
# Answer to Exercise 11.1

use strict;
use warnings;
use File::Find;

# The special array %ENV is predefined, and gives you access to the environmental
# variables such as the name of your home directory, which we use here as the
# starting place for the search.  (We asked for everything on the computer, which
# would be the / directory; but that would also take special permissions on some
# computers (root on Unix) so we'll just use your home directory here.)

find ( \&my_sub, ($ENV{'HOME'}) );

# We'll report all files greater than 10Mbytes in size and older than a year
sub my_sub {
    -f
    and (-s > 10000000)
    and (-A > 365)
    and (print $File::Find::name," ", -s, " bytes ", -A, " days old\n");
}

exit;

